package com.caiyi.financial.nirvana.sms.gateway.http;

import com.caiyi.financial.nirvana.sms.enums.SmsMsgStatusEnum;
import com.caiyi.financial.nirvana.sms.queue.NotifyQueueEntity;
import com.caiyi.financial.nirvana.sms.queue.ReceiveMsgQueueEntity;
import com.caiyi.financial.nirvana.sms.queue.SendQueueEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SampleGateway extends BaseGateway {

    private static final Logger logger = LoggerFactory.getLogger(SampleGateway.class);

    @Override
    public void sendMessage(SendQueueEntity entity) {
        SmsMsgStatusEnum status = SmsMsgStatusEnum.SEND_SUCCESS;
        try {
            //模拟网关发送
            onSubmitResponse(SmsMsgStatusEnum.REQUEST_SUCCESS.index, entity.getMessageId(), "0");
            String result = info.getNotifyResult();
            if ("error".equalsIgnoreCase(result)) {
                status = SmsMsgStatusEnum.SEND_FAIL;
            }
            receiveReport(status.index, entity.getMessageId(), "0");
            logger.info("SampleGateway send success " + entity.getPhone());
        } catch (Exception e) {
            logger.error("SampleGateway error ! ", e);
        }
    }

    @Override
    public boolean notifyStatus(NotifyQueueEntity entity) {
        return true;
    }

    @Override
    public boolean receiveMsg(ReceiveMsgQueueEntity entity) {
        return true;
    }

    @Override
    public int queryBalance() throws Exception {
        return 0;
    }
}
